package crp.core.academic.domain.services;

import crp.core.academic.domain.models.AcademicTermEntity;
import crp.core.academic.domain.models.AcademicYearEntity;
import crp.core.academic.domain.repositories.AcademicTermRepository;
import crp.core.academic.domain.repositories.AcademicYearRepository;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import java.util.Collection;
import java.util.Set;
import java.util.stream.Stream;

@ApplicationScoped
public class AcademicSearcher {
    private final AcademicYearRepository yearRepository;
    private final AcademicTermRepository termRepository;

    @Inject
    public AcademicSearcher(AcademicYearRepository yearRepository,
                            AcademicTermRepository termRepository) {
        this.yearRepository = yearRepository;
        this.termRepository = termRepository;
    }

    public Stream<AcademicYearEntity> years() {
        return yearRepository.findOrderedAll();
    }

    public Stream<AcademicTermEntity> termsByYears(Set<Integer> years) {
        return termRepository.findOrderedByYears(years);
    }

    public AcademicTermEntity currentTerm() {
        return termRepository.findCurrentTerm();
    }

    public Stream<AcademicTermEntity> termsByIds(Collection<String> ids) {
        return termRepository.findByIds(ids);
    }
}
